<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link th:href="@{/css/style.css}" rel="stylesheet" type="text/css"/>
    <th:block th:include="public::common-script"></th:block>
    <script th:src="@{/layer/layer.js}" type="text/javascript"></script>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">行政管理</a></li>
        <li><a href="#">编辑班级</a></li>
    </ul>
</div>

<div class="formbody">

    <div class="formtitle"><span>基本信息</span></div>

    <ul class="forminfo">
        <li><label>班级名称</label><input name="class_name" th:value="${clazz.name}" type="text" class="dfinput"/></li>
        <li><label>入学年份</label>
            <select name="rxnf" type="text" class="dfinput"/>
            <script type="text/javascript" th:inline="javascript">
                var fullYear = new Date().getFullYear();
                for (var i = 2010; i <= fullYear; i++) {
                    if([[${clazz.created}]]==i){
                        document.write("<option selected value='" + i + "'>" + i + "</option>")
                    }else {
                        document.write("<option value='" + i + "'>" + i + "</option>")
                    }
                }
            </script>

            </select>
        </li>
        <li><label> 班主任</label>
            <select name="bzj" type="text" class="dfinput"/>

            </select>
        </li>
        <li><label> 文理科</label>
            <select name="clazzType" type="text" class="dfinput" disabled/>
            <option th:selected="${clazz.type==0}" value="0">文科</option>
            <option th:selected="${clazz.type==1}" value="1">理科</option>
            <option th:selected="${clazz.type==2}" value="2">其他</option>
            </select>
            <i>不建议修改</i>
        </li>
        <li><label>&nbsp;</label><input name="" type="button" onclick="update()" class="btn" value="确认修改"/></li>
    </ul>


</div>

<script type="text/javascript" th:inline="javascript">
    function update() {
        var className = $("[name=class_name]").val()
        var year = $("[name=rxnf]").val()
        var leader = $("[name=bzj]").val()
        var clazzType = $("[name=clazzType]").val()

        if(className==""){
            layer.msg('请输入班级名称', {icon: 5});
            return;
        }
        $.get("/api/updateClazz", {
            id:[[${clazz.id}]],
            name: className,
            leaderId: leader,
            created: year,
            type:clazzType
        }, function (resp) {
            if (resp.code == 200) {
                layer.msg('修改成功', {icon: 1});
                setTimeout(function () {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    parent.location.reload();
                }, 3000)
            }else {
                layer.msg('修改失败', {icon: 2});
            }
        })


    }

    $.get("/api/teacherList", function (resp) {
        var ht = "";
        resp.data.forEach(function (item) {
            if([[${clazz.leader.name}]]==item.name){
                ht += "<option selected value='" + item.id + "'>" + item.name + "</option>"
            }else {
                ht += "<option value='" + item.id + "'>" + item.name + "</option>"
            }
        })
        $("[name=bzj]").html(ht);
    })
</script>
</body>

</html>
